import numpy as np
import matplotlib.pyplot as plt

def brownian_motion(n_steps=1000):
    # 初始化
    steps = np.random.normal(0, np.sqrt(1/n_steps), n_steps)
    position = np.cumsum(steps)

    # 初始位置为0
    position = np.insert(position, 0, 0)

    # 绘制路径
    plt.figure(figsize=(10, 6))
    plt.plot(position)
    plt.title('Brownian Motion Path')
    plt.xlabel('Steps')
    plt.ylabel('Position')
    plt.show()

brownian_motion()
